package com.yingying.service;

import java.util.Date;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yingying.bean.OrderBean;
import com.yingying.dao.OrderDao;

/**
 * @ClassName: AmberBakery
 * @Description:
 * @author chendong
 * @date 2017年4月9日 下午4:21:25
 */
@Service
public class OrderService {
	
	@Resource
	private OrderDao orderdao;
	
	public String insertorder(String name, String infojson) {
		JSONArray arry = JSON.parseArray(infojson);
		String uuid = UUID.randomUUID().toString();
		Date date = new Date(System.currentTimeMillis());
		for (int i = 0; i < arry.size(); i++) {
			JSONObject ob = arry.getJSONObject(i);
			OrderBean order = new OrderBean();
			order.setBakeryName(ob.getString("bakeryname"));
			order.setBuyAmount(Integer.valueOf(ob.getString("buyamount")));
			order.setCostPrice(Double.valueOf(ob.getString("costprice")));
			order.setOrderId(uuid);
			order.setTradeDate(date);
			order.setUserName(name);
			orderdao.insertorder(order);
			System.out.println("插入"+i);
		}
		return "1";
	}
}
